package com.voltbarn.vbsensors;

import java.util.ArrayList;
import java.util.List;

import com.voltbarn.vbsensors.R;

import android.app.ListActivity;
import android.database.Cursor;
import android.os.Bundle;
import android.util.Log;

import android.widget.ArrayAdapter;
import android.widget.SimpleCursorAdapter;


public class MessageList extends ListActivity {
	
	private List<Message> messages;
	
	private VbDBAdapter mDbHelper;

    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        setContentView(R.layout.weather);
        loadFeed();
    }

	private void loadFeed(){
        
        try{
        	BaseFeedParser parser;
        	
	    	parser = new BaseFeedParser("http://api.wunderground.com/weatherstation/WXCurrentObXML.asp?ID=KCAMENDO3");
			messages = parser.parse();

	        parser = new BaseFeedParser("http://api.wunderground.com/weatherstation/WXCurrentObXML.asp?ID=KCAMENDO4");
			messages.addAll(parser.parse());

	    	parser = new BaseFeedParser("http://api.wunderground.com/weatherstation/WXCurrentObXML.asp?ID=KCASANMA24");
		    messages.addAll(parser.parse());
		    
	    	List<String> titles = new ArrayList<String>(messages.size());
	    	for (Message msg : messages){
	    		titles.add(msg.getID());
	    		titles.add(msg.getTemperature());
	    		titles.add(msg.getHumidity());
	    		titles.add(msg.getPressure());
	    		titles.add(msg.getWinds());
	    	}
	    	ArrayAdapter<String> adapter = 
	    		new ArrayAdapter<String>(this, R.layout.otherrow,titles);
	    	this.setListAdapter(adapter);
    	} catch (Throwable t){
    		Log.e("VoltBarnWeather",t.getMessage(),t);
    	}
    }
    
}